<?php

/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/
/**
 * Description of UserQuestion
 *
 * @author hoangle
 */
class User {

    private $db;
    
    public function  __construct() {
        $this->db = Zend_Registry::get('db');
    }

    /**
     * @desc Get user question
     * @param <array> $arrParams (userid)
     * @return <array> data else NULL
     */
    public function getUserInfo($arrParams) {
        try {
            $sql = "SELECT * FROM tblusers";
            $stmt = $this->db->prepare($sql);
            $stmt->execute();
            $rows = $stmt->fetchAll();
            $stmt->closeCursor();
            unset($stmt);
        }
        catch (Zend_Db_Exception $e) {
            throw new Zend_Exception($e);
        }
        return $rows;
    }

    /**
     * @desc Lock User
     * @return <type>
     */
    public function lockUser() {
        try {
            $stmt = $this->db->prepare('CALL sp_getLockUser();');
            $stmt->execute();
            $stmt->closeCursor();
        }
        catch (Zend_Db_Exception $e) {
            throw new Zend_Exception($e);
        }
        return true;
    }

    /**
     * @desc Get user info by username
     * @param <type> $username
     * @return <type>
     */
    public function getAccountByUserName($username) {
        try {
            $sql = "SELECT userid, username, fullname,email, cellphone FROM tblusers 
                WHERE username=:username OR email=:email";
            $stmt = $this->db->prepare($sql);
            $stmt->bindParam(':username', $username, PDO::PARAM_STR);
            $stmt->bindParam(':email', $username, PDO::PARAM_STR);
            $stmt->execute();
            $rows = $stmt->fetch();
            $stmt->closeCursor();
            unset($stmt);
        }
        catch (Zend_Db_Exception $e) {
            throw new Zend_Exception($e);
        }
        return $rows;
    }


    /**
     * @desc update status User
     * @param <array> $arrData
     * @return <bool> true else failed error
     */
    public function updateStatus($arrData) {
        try {
            $sql = "UPDATE tblusers SET status=:p_status WHERE userid=:p_userid";
            $stmt = $this->db->prepare($sql);
            $stmt->bindParam(':p_userid', $arrData['userid'], PDO::PARAM_INT);
            $stmt->bindParam(':p_status', $arrData['status'], PDO::PARAM_INT);
            $stmt->execute();
            $rows = $stmt->fetch();
            $stmt->closeCursor();
            unset($stmt);
        }
        catch (Zend_Db_Exception $e) {
            throw new Zend_Exception($e);
        }
        return $rows;
    }


}

?>
